﻿using System;
using System.Collections.Generic;
class ConvertDecToBin
{
    static int InputNumber()
    {
        while (true)
        {
            try
            {
                int number = int.Parse(Console.ReadLine());
                return number;
            }
            catch (Exception)
            {
                Console.Write("Please re-enter number: ");
            }
        }
    }
    static string DecimalToHexadecimal(int number)
    {
        string hexNum = string.Empty;
        string currentDigit = string.Empty;
        string hexNumAns=string.Empty;
        do
        {
            if (number % 16 > 9)
            {
                switch (number % 16)
                {
                    case 10:
                        {
                            currentDigit = "A";
                            break;
                        }
                    case 11:
                        {
                            currentDigit = "B";
                            break;
                        }
                    case 12:
                        {
                            currentDigit = "C";
                            break;
                        }
                    case 13:
                        {
                            currentDigit = "D";
                            break;
                        }
                    case 14:
                        {
                            currentDigit = "E";
                            break;
                        }
                    case 15:
                        {
                            currentDigit = "F";
                            break;
                        }
                    default:
                        {
                            break;
                        }
                }
            }
            else
            {
                currentDigit = string.Empty + number % 16;
            }
            hexNum = hexNum + currentDigit;
            number = number / 16;
        } while (number > 0);
        for (int i = hexNum.Length-1; i >=0; i--)
        {
            hexNumAns = hexNumAns + hexNum[i];
        }
        return hexNumAns;
    }
    static void Main()
    {
        Console.Write("please input decimal number: ");
        int number = InputNumber();
        string result = DecimalToHexadecimal(number);
        Console.Write("hexadecimal representation of {0} is: ", number);
        Console.WriteLine(result);
        Console.ReadLine();
    }
}



